package com.wyt.controller.tupianController;


import com.wyt.dao.TinstorageMapper;
import com.wyt.dao.ToutstorageMapper;
import com.wyt.dao.TpurchaseMapper;
import com.wyt.entity.StaticTu1Util;
import com.wyt.entity.Tinstorage;
import com.wyt.entity.Tpurchase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class statiscShowChartController {
    @Autowired
    private TinstorageMapper tinstorageMapper;

    @Autowired
    private ToutstorageMapper toutstorageMapper;

    @RequestMapping("/statisc/tu7")
    @ResponseBody
    private List<StaticTu1Util> findAllSumTotprice(){
        Integer d1= tinstorageMapper.FindAllSumtotprice();
        Integer d2= toutstorageMapper.FindAllSumtotprice();

        StaticTu1Util tu1Util = new StaticTu1Util("入库总金额", d1);
        StaticTu1Util tu2Util= new StaticTu1Util("出库总金额", d2);

        List<StaticTu1Util> list=new ArrayList<>();
        list.add(tu1Util);
        list.add(tu2Util);
        return list;
    }

    @Autowired
    private TpurchaseMapper tpurchaseMapper;

    @RequestMapping("purchase/statisc/tu4")
    @ResponseBody
    private List<StaticTu1Util> findAllPidAndNameCount() {
        List<Tpurchase> list = tpurchaseMapper.findAllPidAndNameCount();
        List<StaticTu1Util> list1 = new ArrayList<>();
        for (Tpurchase t : list
        ) {
            String str = t.getPname() + " " + t.getUid();
            StaticTu1Util tu1Util = new StaticTu1Util(str, t.getPidNameCount());
            list1.add(tu1Util);
        }
        return list1;
    }

    @RequestMapping("/inStorage/statisc/tu5")
    @ResponseBody
    private Map<String,List> findAllPidAndNameCountPrice(){

        Map<String,List> map=new HashMap<>();
        List<Tinstorage> list=tinstorageMapper.findAllInstroageUidPnameAndCount();
        List list1=new ArrayList();
        List list2=new ArrayList();

        for (Tinstorage t:list
        ) {
            String str=t.getPname()+" "+t.getUid();
            list1.add(str);
            list2.add(t.getCountPname());
        }
        map.put("name",list1);
        map.put("value",list2);
        return map;
    }


}
